<?php
class RoleController{
	
	function findAll(){
		$objDB = $GLOBALS['objDB'];
		$rsR = $objDB->Execute("SELECT * FROM roles ;");
		while (!$rsR->EOF) {
			$r = new Role($rsR->fields['ID'],$rsR->fields['NAME']);
			$roles[] = $r ; 
			$rsR->MoveNext();
		}
		return $roles;
	}
	
	function save($entRole){
		$objDB = $GLOBALS['objDB'];
		$rsR = $objDB->Execute("SELECT * FROM roles WHERE ID='0' ;");
		$arrRecords['ID'] = $entRole->id;
		$arrRecords['NAME'] = $entRole->name;
		$strInserSql = $objDB->GetInsertSQL($rsR,$arrRecords);
		$objDB->Execute($strInserSql);
		return true;
	}
	
	function find($id) {
		$objDB = $GLOBALS['objDB'];
		$rsR = $objDB->Execute("SELECT * FROM roles WHERE ID='$id' ;");
		$role = new Role($rsR->fields['ID'],$rsR->fields['NAME']);
		return $role;
	}
	
	function update($entRole){
		$objDB = $GLOBALS['objDB'];
		$objDB->Execute("UPDATE roles SET NAME='$entRole->name' WHERE ID='$entRole->id' ;");
		return true;
	}
	
	function delete($id){
		$objDB = $GLOBALS['objDB'];
		$objDB->Execute("DELETE FROM roles WHERE ID='$id' ;");
		return true;
	}
}
?>